#include <regx52.h>

sfr AUXR = 0x8E;
sbit LED1 = P2^0;

unsigned char timer_0_count = 0;
unsigned char led_lux = 10;//0~19

void timer_0_isr() interrupt 1 
{
	TL0 = 0xD2;	
	TH0 = 0xFF;
	if(timer_0_count++ == 20) {
		timer_0_count = 0;
	}
//	if(led_lux == 255) {
//		led_lux = 0;
//	} else if(led_lux == 20 ) {
//		led_lux = 19;
//	}	
	LED1 = timer_0_count >= led_lux;
}

void Timer0_Init(void)
{
	TMOD &= 0xF0;
	TMOD |= 0x01;//timer 0 mode 01  16bit no reload
	TL0 = 0xD2;	
	TH0 = 0xFF;//11.0592MHZ  12T  50us
	ET0 = 1;  //timer 0 interrupt enable
	EA = 1;   //enable all interrupts
	TF0 = 0;  //clear timer 0 interrupt flag 
	TR0 = 1;  //timer 0 run 
}